import { Request, Response } from 'express'
import { getSuggestion, optimizePrompt, generateDescription } from '../services/ai'
import { logger } from '../services/logger'

// 获取 AI 建议
export const getAISuggestion = async (req: Request, res: Response) => {
    try {
        const suggestion = await getSuggestion(req.body.param, req.body.value)
        res.json({ suggestion })
    } catch (error) {
        logger.error('AI suggestion error:', error)
        res.status(500).json({ error: '获取 AI 建议失败' })
    }
}

// 优化提示词
export const optimizePromptText = async (req: Request, res: Response) => {
    try {
        const optimized = await optimizePrompt(req.body.prompt)
        res.json({ optimized })
    } catch (error) {
        logger.error('Prompt optimization error:', error)
        res.status(500).json({ error: '提示词优化失败' })
    }
}

// 生成工作流描述
export const generateWorkflowDescription = async (req: Request, res: Response) => {
    try {
        const description = await generateDescription(req.body.workflow)
        res.json({ description })
    } catch (error) {
        logger.error('Description generation error:', error)
        res.status(500).json({ error: '生成描述失败' })
    }
} 